import 'dart:convert';
import 'dart:io';

Future<void> futureTest() async {
  ProcessResult results = await Process.run('dir', ['/4'], runInShell: true);
  print(results.stdout);
  Process.run('dir', ['/O'], runInShell: true).then((res) {
    print(res.stdout);
  });

  final process = await Process.start('git', ['log'], runInShell: true);
  var lineStream =
      process.stdout.transform(Utf8Decoder()).transform(LineSplitter());
  await for (var line in lineStream) {
    print(line);
  }

  await process.stderr.drain();
  print('exit code: ${await process.exitCode}');

  final output = File('output.txt').openWrite();
  Process p = await Process.start('git', ['log']);

  // Wait for the process to finish; get the exit code.
  final exitCode = (await Future.wait([
    p.stdout.pipe(output), // Send stdout to file.
    p.stderr.drain(), // Discard stderr.
    p.exitCode
  ]))[2];

  print('exit code: $exitCode');
}

void main() {
  futureTest();
}
